package com.meihua.shellapp.dialog;

import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment;
import android.view.Gravity;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.LinearInterpolator;
import android.widget.ImageView;

import com.meihua.shellapp.R;



public class LoadingDialog extends DialogFragment {

    private Dialog mDialog;

    @NonNull
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        if (mDialog == null) {
            mDialog = new Dialog(getActivity(), R.style.loading_dialog);
            mDialog.setContentView(R.layout.loading_layout);
            mDialog.setCancelable(false);
            mDialog.getWindow().setGravity(Gravity.CENTER);

            View view = mDialog.getWindow().getDecorView();
            ImageView img = view.findViewById(R.id.mouse);
            Animation circle_anim = AnimationUtils.loadAnimation(getContext(), R.anim.loading_img_anim);
            LinearInterpolator interpolator = new LinearInterpolator();  //设置匀速旋转，在xml文件中设置会出现卡顿
            circle_anim.setInterpolator(interpolator);
            if (circle_anim != null) {
                img.startAnimation(circle_anim);  //开始动画
            }
        }
        return mDialog;
    }

    @Override
    public void onDismiss(DialogInterface dialog) {
        super.onDismiss(dialog);
        mDialog = null;
        System.gc();
    }

}
